import React from 'react';
import { connect } from 'dva';
import { createForm } from 'rc-form';
import styles from './index.less';
import {Toast,List,InputItem,Button,Modal,WingBlank,WhiteSpace,Switch } from 'antd-mobile';
import {routerRedux} from 'dva/router';
import Block from 'fs-flex'
import Header from '../../../../../../components/Header/index'
import SysBusiTypeService from '../../../../../../services/sysBusiTypeService'
import BusiTypeService from '../../../../../../services/busiTypeService'

const alert = Modal.alert

class SettingPage extends React.Component{
  state={
      show:false,
  }
  componentDidMount(){
  }

  async save(){
      const {form} =this.props;
      const {busitypename,busitypecount,timecount1,timecount2,timecount3,timecount4,timecount5,timecount6,timecount7,
      Switch1,Switch2,Switch3,Switch4,Switch5,Switch6,Switch7} = form.getFieldsValue()

      if((!timecount1&&Switch1)||(!timecount2&&Switch2)||(!timecount3&&Switch3)||(!timecount4&&Switch4)||(!timecount5&&Switch5)||(!timecount6&&Switch6)||(!timecount7&&Switch7)){
          Toast.fail('请填写时段业务上限！',2)
          return
      }

      // if(!timecount1||!timecount2||!timecount3||!timecount4||!timecount5||!timecount6||!timecount7){
      //     Toast.fail('请填写时段业务上限',2)
      //     return
      // }

      if(!busitypename){
          Toast.fail('请填写业务类型名称！',2)
          return
      }

      if(!busitypecount){
          Toast.fail('请填写业务类型名称！',2)
          return
      }

      let params=[
          {
            busitypename:busitypename,
            busitype_count:busitypecount,
            time_start:'09:00',
            time_end:'10:00',
            time_count:timecount1,
            time_enable:Switch1
          },
          {
            busitypename:busitypename,
            busitype_count:busitypecount,
            time_start:'10:00',
            time_end:'11:00',
            time_count:timecount2,
            time_enable:Switch2
          },
          {
            busitypename:busitypename,
            busitype_count:busitypecount,
            time_start:'11:00',
            time_end:'12:00',
            time_count:timecount3,
            time_enable:Switch3
          },
          {
            busitypename:busitypename,
            busitype_count:busitypecount,
            time_start:'13:00',
            time_end:'14:00',
            time_count:timecount4,
            time_enable:Switch4
          },
          {
            busitypename:busitypename,
            busitype_count:busitypecount,
            time_start:'14:00',
            time_end:'15:00',
            time_count:timecount5,
            time_enable:Switch5
          },
          {
            busitypename:busitypename,
            busitype_count:busitypecount,
            time_start:'15:00',
            time_end:'16:00',
            time_count:timecount6,
            time_enable:Switch6
          },
          {
            busitypename:busitypename,
            busitype_count:busitypecount,
            time_start:'16:00',
            time_end:'17:00',
            time_count:timecount7,
            time_enable:Switch7
          }
      ]
      const {code,msg} = await SysBusiTypeService.addBusiType(params)
      if(code==="0000"){
          Toast.info("添加成功！",3)
          setTimeout(() => {
              this.props.history.push('/manage/sysBusiType')
          }, 2000);
      }
  }

  render(){
      const { getFieldProps  } = this.props.form;
      return(
          <Block vf className={styles.busiContent}>
              <Block>
                  <Header title='业务类型编辑' needBack="true" history={this.props.history}/>
              </Block>
              <WingBlank size="lg">
                  <WhiteSpace size="lg" />
                      <List>
                          <List.Item>
                              <InputItem
                                  {...getFieldProps('busitypename', { initialValue:"" })}
                                  clear
                                  placeholder="请输入业务业务名称"
                                  ref={el => this.autoFocusInst = el}>
                              </InputItem>
                              <Block className={styles.ipt1}>
                                  <InputItem
                                      {...getFieldProps('busitypecount', { initialValue:"100" })}
                                      clear
                                      type="number"
                                      placeholder="请输入业务每日上限数，只能为整数"
                                      ref={el => this.autoFocusInst = el}>每日临时排号上限
                                  </InputItem>
                              </Block>

                              <Block wf>
                                  <Block w={140} className={styles.ipt2}>
                                      <InputItem value="时段"  editable={false}></InputItem>
                                  </Block>
                                  <Block w={70}>
                                      <InputItem value="号数"  editable={false}></InputItem>
                                  </Block>
                                  <Block f='1' className={styles.ipt4}>
                                        <InputItem value="启用状态"  editable={false}></InputItem>
                                  </Block>
                              </Block>

                              <Block wf>
                                  <Block w={140} className={styles.ipt2}>
                                      <InputItem value="09:00-10:00"  editable={false}></InputItem>
                                  </Block>
                                  <Block w={60}>
                                      <InputItem
                                          {...getFieldProps('timecount1', { initialValue:"20" })}
                                          clear
                                          type="number"
                                          ref={el => this.autoFocusInst = el}>
                                      </InputItem>
                                  </Block>
                                  <Block f='1' className={styles.ipt4}>
                                      <List.Item
                                    extra={<Switch
                                    {...getFieldProps('Switch1', {
                                      initialValue: true,
                                      valuePropName: 'checked',
                                    })}
                                    />}
                                    ></List.Item>
                                  </Block>
                              </Block>
                              <Block wf>
                                    <Block w={140} className={styles.ipt2}>
                                  <InputItem value="10:00-11:00"  editable={false}></InputItem>
                                      </Block>
                                      <Block w={60}>
                                      <InputItem
                                    {...getFieldProps('timecount2', { initialValue:"20" })}
                                    clear
                                    type="number"
                                    ref={el => this.autoFocusInst = el}>
                                  </InputItem>
                                    </Block>
                                    <Block f='1' className={styles.ipt4}>
                                  <List.Item
                                    extra={<Switch
                                    {...getFieldProps('Switch2', {
                                      initialValue: true,
                                      valuePropName: 'checked',
                                    })}
                                    />}
                                    ></List.Item>
                                    </Block>
                              </Block>
                              <Block wf>
                                  <Block w={140} className={styles.ipt2}>
                                <InputItem value="11:00-12:00"  editable={false}></InputItem>
                                    </Block>
                                    <Block w={60}>
                                    <InputItem
                                  {...getFieldProps('timecount3', { initialValue:"20" })}
                                  clear
                                  type="number"
                                  ref={el => this.autoFocusInst = el}>
                                </InputItem>
                                  </Block>
                                  <Block f='1' className={styles.ipt4}>
                                <List.Item
                                  extra={<Switch
                                  {...getFieldProps('Switch3', {
                                    initialValue: true,
                                    valuePropName: 'checked',
                                  })}
                                  />}
                                  ></List.Item>
                                  </Block>
                              </Block>

                              <Block wf>
                                  <Block w={140} className={styles.ipt2}>
                                <InputItem value="13:00-14:00"  editable={false}></InputItem>
                                    </Block>
                                    <Block w={60}>
                                    <InputItem
                                  {...getFieldProps('timecount4', { initialValue:"20" })}
                                  clear
                                  type="number"
                                  ref={el => this.autoFocusInst = el}>
                                </InputItem>
                                  </Block>
                                  <Block f='1' className={styles.ipt4}>
                                <List.Item
                                  extra={<Switch
                                  {...getFieldProps('Switch4', {
                                    initialValue: true,
                                    valuePropName: 'checked',
                                  })}
                                  />}
                                  ></List.Item>
                                  </Block>
                              </Block>

                              <Block wf>
                                  <Block w={140} className={styles.ipt2}>
                                <InputItem value="14:00-15:00"  editable={false}></InputItem>
                                    </Block>
                                    <Block w={60}>
                                    <InputItem
                                  {...getFieldProps('timecount5', { initialValue:"20" })}
                                  clear
                                  type="number"
                                  ref={el => this.autoFocusInst = el}>
                                </InputItem>
                                  </Block>
                                  <Block f='1' className={styles.ipt4}>
                                <List.Item
                                  extra={<Switch
                                  {...getFieldProps('Switch5', {
                                    initialValue: true,
                                    valuePropName: 'checked',
                                  })}
                                  />}
                                  ></List.Item>
                                  </Block>
                              </Block>

                              <Block wf>
                                  <Block w={140} className={styles.ipt2}>
                                <InputItem value="15:00-16:00"  editable={false}></InputItem>
                                    </Block>
                                    <Block w={60}>
                                    <InputItem
                                  {...getFieldProps('timecount6', { initialValue:"20" })}
                                  clear
                                  type="number"
                                  ref={el => this.autoFocusInst = el}>
                                </InputItem>
                                  </Block>
                                  <Block f='1' className={styles.ipt4}>
                                <List.Item
                                  extra={<Switch
                                  {...getFieldProps('Switch6', {
                                    initialValue: true,
                                    valuePropName: 'checked',
                                  })}
                                  />}
                                  ></List.Item>
                                  </Block>
                              </Block>

                              <Block wf>
                                  <Block w={140} className={styles.ipt2}>
                                <InputItem value="16:00-17:00"  editable={false}></InputItem>
                                    </Block>
                                    <Block w={60}>
                                    <InputItem
                                  {...getFieldProps('timecount7', { initialValue:"20" })}
                                  clear
                                  type="number"
                                  ref={el => this.autoFocusInst = el}>
                                </InputItem>
                                  </Block>
                                  <Block f='1' className={styles.ipt4}>
                                <List.Item
                                  extra={<Switch
                                  {...getFieldProps('Switch7', {
                                    initialValue: true,
                                    valuePropName: 'checked',
                                  })}
                                  />}
                                  ></List.Item>
                                  </Block>
                              </Block>
                          </List.Item>
                    </List>
                  <WhiteSpace size="lg" />
                  <Block wf mt={15}>
                      <Block f='3'></Block>
                      <Block f='4'><Button a='c' f='c' size='small' type="primary" onClick={() =>
                          this.save()}
                      >保存</Button></Block>
                    <Block f='3'></Block>
                  </Block>
              </WingBlank>
          </Block>
      );
  }
}

SettingPage
  .propTypes = {
};

export default createForm()(connect()(SettingPage));
